var $$ = jQuery.noConflict();
(function($, doc) {
    document.documentElement.style.fontSize = document.documentElement.clientWidth / 6.4 + 'px';
    $.init();
    $.ready(function() {
        //获取上一页数据
        var data=JSON.parse(localStorage.getItem('userInfo'))
        var orderId;//360所需
        console.log(data)
        //form表单
        $$('#send').on('click', function() {
            var i = 0,k=0;
            mui("#formData input").each(function() {
                if(!this.value || this.value.trim() == "") {
                    var label = this.previousElementSibling;
                    mui.alert(label.innerText + "不允许为空");
                    return false;
                } else {
                    i = i + 1
                }
            });
            var _send=mui(this)
            mui('.phone').each(function () {
                if(/^(0|86|17951)?(13[0-9]|15[012356789]|17[678]|18[0-9]|14[57])[0-9]{8}$/.test($$(this).val())){
                    k=k+1
                }else {
                    mui.alert('手机号码格式不正确');
                }
            })
            if (i == 15&&k==5) {
                _send.button('loading');
                var contactArr=[]
                mui('.contact').each(function () {
                    var obj={
                        'contact':$$(this).find('input').eq(0).val(),
                        'name':$$(this).find('input').eq(1).val(),
                        'phones':$$(this).find('input').eq(2).val()
                    }
                    contactArr.push(obj)
                })
                data.contactInfo = JSON .stringify(contactArr)
                localStorage.setItem('userInfo',JSON.stringify(data))
                $.ajax({
                    url:'/orderInfo/applyFromWechat',
                    data:data,
                    type:'POST',
                    headers:{"Content-Type":"application/json"},
                    success:function(res){
                        if(res.code==10010){
                            orderId=res.obj
                            localStorage.setItem('orderId',res.obj)
                             threeApi('mobile',orderId)
                        }
                        else{
                            mui('#send').button('reset');
                            mui.alert(res.message);
                        }
                    }
                })
            }
        })
        //360
        function threeApi(a,orderId) {
            $$.post('/rong360/collectUser/' + a,{'orderId':orderId}, function (data) {
                console.log(data)
                if (data.success) {
                    mui('#send').button('reset');
                    openPage(data.data.tianji_api_tianjireport_collectuser_response.redirectUrl)
                } else {
                    mui.alert(data.msg)
                }
            })
        }
    });
})(mui, document);